//
//  AppDelegate.swift
//  web
//
//  Created by 张卓 on 2017/1/16.
//  Copyright © 2017年 ZZ. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?



    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool{

//        let s =  ZZEmoticonTools.shared.loadEmoticonGroupArray(emoticons: ZZEmoticonTools.shared.emojiEmoticons)
        
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.backgroundColor = UIColor.white
        self.window?.rootViewController = setupRootViewController()
        self.window?.makeKeyAndVisible()
        //注册通知  监听切换跟控制器
        NotificationCenter.default.addObserver(self, selector: #selector(switchRootViewCotoller), name: NSNotification.Name(rawValue: SWITCHROOTVIEWCONTROLLERNOTI), object: nil)
        
        return true
    }
    //访客视图->登录界面->欢迎界面 objrct = nil
    //
    
    @objc private func switchRootViewCotoller(noti:Notification){
//        if noti.object == nil {
//            window?.rootViewController = ZZWelcomeViewController()
//        }else{
//            window?.rootViewController = ZZMainViewController()
//        }
        window?.rootViewController = noti.object == nil ?ZZWelcomeViewController() : ZZMainViewController()
    }
    
    
    /*
        - 程序启动的时候 选择根视图
            - 如果没有登录 rootVC = ZZMainVC
            - 如果登录了.  rootVC = ZZWelcomeVC
     */
    //设置跟控制器
    private func setupRootViewController() -> UIViewController{
        //如果没有登录
//        if ZZOAuthViewModel.shared.isLogin{
//            return ZZMainViewController()
//        }else {
//            return ZZWelcomeViewController()
//        }
        return !ZZOAuthViewModel.shared.isLogin == true ? ZZMainViewController() : ZZWelcomeViewController()
    }
    
    
    //析构函数
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    


}

